using System;
using System.Linq;
using System.Reflection;
using CommandSystem;

namespace CustomCharacter.Commands.CustomCharacterCommands
{
    public class List : ICommand
    {
        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (!sender.CheckPermission(PlayerPermissions.ForceclassWithoutRestrictions))
            {
                response = "你没有权限使用此命令！";
                return false;
            }

            response = "所有自定义角色状态：";
            foreach (var item in CustomCharacterPlugin.instance.Manager.AllTypes.Keys)
            {
                var attr = item.GetCustomAttribute<RoleInfoAttribute>();
                response += $"\n{attr.Name} ({item.Name})";
                foreach (var p in CustomCharacter.AllCharacters.Where(x => x.GetType() == item))
                    response += $"[{p.Player.Nickname}] ";
            }

            response += "\n----------------";
            return true;
        }

        public string Command { get; } = "list";
        public string[] Aliases { get; } = Array.Empty<string>();
        public string Description { get; } = "获取自定义角色列表";
    }
}